package com.kaili.basic.service.impl;

import com.baomidou.mybatisplus.plugins.Page;
import com.kaili.basic.mapper.BaseCategoryMapper;
import com.kaili.basic.pojo.dto.BaseCategoryAddDto;
import com.kaili.basic.pojo.dto.BaseCategoryQueryDto;
import com.kaili.basic.pojo.entity.BaseAllCategory;
import com.kaili.basic.pojo.entity.BaseCategory;
import com.kaili.basic.pojo.entity.BaseCategoryExport;
import com.kaili.basic.service.BaseCategoryService;
import com.kaili.common.util.LoginDetailUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
@Service
public class BaseCategoryServiceImpl implements BaseCategoryService {

    @Autowired
    private BaseCategoryMapper categoryMapper;

    @Override
    public void addCategory(BaseCategoryAddDto addDto) {
        Integer uid = LoginDetailUtils.getCurrentEmployeeId();
        BaseCategory category = new BaseCategory();
        BeanUtils.copyProperties(addDto, category);
        if (uid != null) {
            category.setCreateBy(uid.longValue());
            category.setCreateTime(new Date());
            categoryMapper.addCategory(category);
        }
    }

    @Override
    public void deleteCategory(Long categoryId) {
        categoryMapper.deleteCategory(categoryId);
    }

    @Override
    public void updateCategory(BaseCategoryAddDto addDto) {
        Integer uid = LoginDetailUtils.getCurrentEmployeeId();
        BaseCategory category = new BaseCategory();
        BeanUtils.copyProperties(addDto, category);
        if (uid != null) {
            category.setModifyBy(uid.longValue());
            category.setModifyTime(new Date());
            categoryMapper.updateCategory(category);
        }
    }

    @Override
    public Page<BaseCategory> queryCategory(Page<BaseCategory> page, BaseCategoryQueryDto category) {
        List<BaseCategory> list = categoryMapper.queryCategory(page, category);
        return page.setRecords(list);
    }

    @Override
    public List<BaseCategoryExport> queryCategoryExport(BaseCategoryQueryDto queryDto) {
        return categoryMapper.queryCategoryExport(queryDto);
    }

    @Override
    public List<BaseAllCategory> queryAllCategory() {
        return categoryMapper.queryAllCategory();
    }

    @Override
    public String getCategoryCode() {
        return categoryMapper.getCategoryCode();
    }
}
